﻿Imports DevComponents.DotNetBar
Imports TNCBAL
Imports TNCDAL

Public Class frmMain
    '****************THANH LÀM******************************
    Private Sub SetEnableSomeMenus(ByVal val As Boolean)
        For Each tabItem As DevComponents.DotNetBar.RibbonTabItem In RibbonControl1.Items
            Dim panel As DevComponents.DotNetBar.RibbonPanel = tabItem.Panel
            For Each bar As DevComponents.DotNetBar.RibbonBar In panel.Controls
                For Each item As DevComponents.DotNetBar.BaseItem In bar.Items
                    Try
                        item.Enabled = val
                    Catch ex As Exception
                    End Try
                Next

            Next
        Next
        ButtonItemLogin.Enabled = Not val
        'ButtonItemChangeConnectDB.Enabled = True
    End Sub

    Private Sub EnableMenuByRoles()

        '**************THỰC HIỆN SET MENU THEO QUYỀN************************
        'THANH SỬA NGÀY 13/12/2013
        Dim ctrlRoleMenu As New CRoleMenuController
        Dim idRole As Integer = GeneralClassBAL._User.ID_Role
        For Each tabItem As DevComponents.DotNetBar.RibbonTabItem In RibbonControl1.Items
            Dim panel As DevComponents.DotNetBar.RibbonPanel = tabItem.Panel
            For Each bar As DevComponents.DotNetBar.RibbonBar In panel.Controls
                For Each item As DevComponents.DotNetBar.BaseItem In bar.Items
                    Try
                        If (ctrlRoleMenu.CheckMenuInRoleByName(idRole, item.Text) = True) Then
                            item.Enabled = True
                        End If
                    Catch ex As Exception
                    End Try
                Next

            Next
        Next
        'disable menu dang nhap
        ButtonItemLogin.Enabled = False
        ButtonItemLogout.Enabled = True
        ButtonItemChangePass.Enabled = True
        '***************HẾT PHẦN SET MENU THEO QUYỀN************************
    End Sub

    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        RibbonTabItemSystem.Select()
        Bar2.DockTabCloseButtonVisible = True
        SetEnableSomeMenus(False)
        Dim frm As New frmLogin
        frm.ShowDialog()
        If LoginOK Then
            EnableMenuByRoles()
            'If GeneralClassBAL._User.ID_Role <> enumROLE.GUEST Then
            '    ButtonItemExportFiles_Click(Nothing, Nothing)
            'End If
            If GeneralClassBAL._User.ID_Role = enumROLE.ADMINISTRATOR Then
                btAccessPermission.Enabled = True
            End If
            'Load form mặc định
            'kiểm tra xem user này có được load form không
            Dim ctrlRoleMenu As New CRoleMenuController
            If (ctrlRoleMenu.CheckMenuInRoleByName(GeneralClassBAL._User.ID_Role, "Export Files") = True) Then
                ButtonItemExportFiles_Click(Nothing, Nothing)
            End If
        End If
    End Sub
    '*****************HẾT PHẦN THANH LÀM*****************************

    'Private Sub SetEnableSomeMenus(ByVal val As Boolean)
    '    For Each tabItem As DevComponents.DotNetBar.RibbonTabItem In RibbonControl1.Items
    '        Dim panel As DevComponents.DotNetBar.RibbonPanel = tabItem.Panel
    '        For Each bar As DevComponents.DotNetBar.RibbonBar In panel.Controls
    '            For Each item As DevComponents.DotNetBar.BaseItem In bar.Items
    '                Try
    '                    item.Enabled = val
    '                Catch ex As Exception
    '                End Try
    '            Next

    '        Next
    '    Next
    '    ButtonItemLogin.Enabled = Not val
    '    ButtonItemChangeConnectDB.Enabled = True

    'End Sub

    'Private Sub EnableMenuByRoles()
    '    'disable menu dang nhap
    '    ButtonItemLogin.Enabled = False
    '    ButtonItemLogout.Enabled = True
    '    ButtonItemChangePass.Enabled = True
    '    'Try
    '    '    'thuc hien hien thi cac menu tren form

    '    '    For Each Menu As String In dsQuyenTrenForm
    '    '        For Each ctrl As Control In Me.Controls
    '    '            If ctrl.Name Is "MenuStrip1" Then
    '    '                Dim tool() As ToolStripItem = MenuStrip1.Items.Find(Trim(Menu), True)
    '    '                If tool.Length > 0 Then
    '    '                    tool(0).Enabled = True
    '    '                End If
    '    '            End If
    '    '            If ctrl.Name = "ToolStrip1" Then
    '    '                Dim strToolStripButtonName As String = Menu.Substring(0, Menu.Length - CStr("ToolStripMenuItem").Length) + "ToolStripButton"
    '    '                Dim tool2() As ToolStripItem = ToolStrip1.Items.Find(strToolStripButtonName, True)
    '    '                If tool2.Length > 0 Then
    '    '                    tool2(0).Enabled = True
    '    '                End If
    '    '            End If
    '    '        Next
    '    '    Next
    '    'Catch ex As Exception
    '    'End Try
    'End Sub

    'Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    '    RibbonTabItemSystem.Select()
    '    Bar2.DockTabCloseButtonVisible = True
    '    SetEnableSomeMenus(False)
    '    If Not GeneralClassBAL.CheckConnectString() Then
    '        MessageBox.Show("ConnectString của DataContext không trùng với App.config")
    '        Return
    '    End If
    '    Dim frm As New frmLogin
    '    frm.ShowDialog()
    '    If LoginOK Then
    '        EnableMenuByRoles()
    '        'If GeneralClassBAL._User.ID_Role <> enumROLE.GUEST Then
    '        '    ButtonItemExportFiles_Click(Nothing, Nothing)
    '        'End If
    '        SetEnableSomeMenus(True)
    '        'Kiểm tra vai trò có là admin hay vai trò khác
    '        If GeneralClassBAL._User.ID_Role = enumROLE.ADMINISTRATOR Then

    '        Else
    '            'Enable/Disable các chức năng theo phân quyền
    '            EnableMenuByRoles()

    '            'Load form mặc định
    '            ButtonItemExportFiles_Click(Nothing, Nothing)

    '        End If
    '    End If
    'End Sub

    Public Sub UpdateDocContainerItem(ByVal name As String, ByVal title As String)
        Dim dockName As String = "DockContainerItem" + name
        Me.Bar2.SelectedDockContainerItem.Text = title
        Me.Bar2.SelectedDockContainerItem.Name = dockName
    End Sub

    Private Sub CreateNewDock(ByVal dockName As String, ByVal name As String, ByVal title As String, ByVal uc As UserControl)
        Dim panelDockContainer As New DevComponents.DotNetBar.PanelDockContainer
        Dim dockContainerItem As New DevComponents.DotNetBar.DockContainerItem

        Me.Bar2.Controls.Add(panelDockContainer)
        Me.Bar2.Items.AddRange(New DevComponents.DotNetBar.BaseItem() {dockContainerItem})

        '
        'dockContainerItem
        '
        dockContainerItem.Control = panelDockContainer
        dockContainerItem.Name = dockName
        dockContainerItem.Text = title
        '
        'panelDockContainer
        '
        panelDockContainer.Controls.Add(uc)
        panelDockContainer.Location = New System.Drawing.Point(3, 28)
        panelDockContainer.Name = "PanelDockContainer" + name
        panelDockContainer.Size = New System.Drawing.Size(804, 374)
        panelDockContainer.Style.Alignment = System.Drawing.StringAlignment.Center
        panelDockContainer.Style.BackColor1.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.BarBackground
        panelDockContainer.Style.BackColor2.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.BarBackground2
        panelDockContainer.Style.BorderColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.BarDockedBorder
        panelDockContainer.Style.ForeColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.ItemText
        panelDockContainer.Style.GradientAngle = 90
        panelDockContainer.TabIndex = Me.Bar2.Items.Count
        uc.Dock = DockStyle.Fill
        Bar2.SelectedDockContainerItem = dockContainerItem
    End Sub


    Public Sub AddNewDockContainerItem(ByVal name As String, ByVal title As String, ByVal uc As UserControl)
        Dim count1 As Integer = Bar2.Items.Count
        Dim count As Integer = Bar2.Controls.Count

        Bar2.Visible = True
        Dim dockName As String = "DockContainerItem" + name
        'Kiểm tra đã load dockName chưa, nếu chưa thì tạo mới
        If Not Me.Bar2.Items.Contains(dockName) Then
            CreateNewDock(dockName, name, title, uc)
        Else
            'Nếu form này đã load rồi thì remove nó
            If Bar2.Items.Contains(dockName) Then
                Bar2.Items.Remove(dockName)
                AddNewDockContainerItem(name, title, uc)
            End If
        End If

        Dim count2 As Integer = Bar2.Items.Count
        Dim count3 As Integer = Bar2.Controls.Count
    End Sub

    Public Sub AddNewDockCategoriesItem(ByVal name As String, ByVal title As String, ByVal uc As UserControl)
        Dim count1 As Integer = Bar2.Items.Count
        Dim count As Integer = Bar2.Controls.Count

        Bar2.Visible = True
        Dim dockName As String = "DockContainerItem" + name
        'Kiểm tra đã load dockName chưa, nếu chưa thì tạo mới
        If Not Me.Bar2.Items.Contains(dockName) Then
            CreateNewDock(dockName, name, title, uc)
        Else 'Nếu form này đã load rồi thì focus nó
            Bar2.Items(dockName).Visible = True
            Bar2.SelectedDockContainerItem = Bar2.Items(dockName)
        End If

        Dim count2 As Integer = Bar2.Items.Count
        Dim count3 As Integer = Bar2.Controls.Count
    End Sub

    Private Sub ButtonItemCompany_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonItemCustomer.Click
        AddNewDockContainerItem("CompanyManagement", "Company/Customer", New ucCategories(enumCategories.Company))
    End Sub

    Private Sub ButtonItemBackup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonItemBackup.Click
        'Dim frm As New frmBackup
        'frm.ShowDialog()
        AddNewDockContainerItem("BackupDatabase", "Backup Database", New ucBackup)
    End Sub

    Private Sub ButtonItemChangePass_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonItemChangePass.Click
        If (GeneralClassBAL._User IsNot Nothing) Then
            Dim frm As New frmChangePass(GeneralClassBAL._User.ID_User)
            frm.ShowDialog()
        End If
    End Sub

    Private Sub ButtonItemUserManagement_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonItemUserManagement.Click
        'Dim frm As New frmManageUsers
        'frm.ShowDialog()
        Dim uc As New ucManageUsers
        AddNewDockCategoriesItem("ManageUsers", "Manage Users", uc)
    End Sub

    Private Sub ButtonItemUser_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        'Dim frm As New frmUser
        'frm.ShowDialog()
    End Sub

    Private Sub ButtonItemLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonItemLogin.Click
        frmMain_Load(Nothing, Nothing)
    End Sub

    Private Sub ButtonItemTemp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        'Dim frm As New frmTemp
        'frm.ShowDialog()
    End Sub

    Private Sub ButtonItemLogs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonItemSystemLogs.Click
        AddNewDockContainerItem("SystemLogs", "System Logs", New ucSystemLog)
    End Sub

    Private Sub ButtonItemContType_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonItemContType.Click
        'AddNewDockContainerItem("ContainerType", "Container Type", New ucContType)
        AddNewDockCategoriesItem("ContainerType", "Container Type", New ucCategories(enumCategories.ContainerType))
    End Sub

    Private Sub ButtonItemRefreshDatabase_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonItemRefreshDatabase.Click
        AddNewDockContainerItem("RefreshDatabase", "Refresh Database", New ucRefreshDatabase)
    End Sub

    Private Sub ButtonItemDemDet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonItemWarehouse.Click
        'AddNewDockContainerItem("DemDetManagement", "Dem/Det Management", New ucDemDet)
        AddNewDockCategoriesItem("DemDetManagement", "Dem/Det Management", New ucCategories(enumCategories.DemDet))
    End Sub

    Private Sub btnDriver_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDriver.Click
        AddNewDockCategoriesItem("DriverList", "Driver List", New ucCategories(enumCategories.Driver))
    End Sub

    Private Sub btnTruck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTruck.Click
        AddNewDockCategoriesItem("TruckList", "Truck List", New ucCategories(enumCategories.Truck))
    End Sub

    Private Sub btnCurrency_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCurrency.Click
        'Dim frm As New frmCurrencies
        'frm.ShowDialog()
        AddNewDockCategoriesItem("CurrencyList", "Currency List", New ucCategories(enumCategories.Currency))

    End Sub

    Private Sub btnGood_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGood.Click
        AddNewDockCategoriesItem("GoodType", "GoodType", New ucCategories(enumCategories.Good))

    End Sub

    Private Sub btUser_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        'Dim frmUser As New frmEditUser
        'frmUser.ShowDialog()
        'Dim uc As New ucEditUser
        'AddNewDockCategoriesItem("Edit user", "Edit user", uc)

    End Sub

    Private Sub ButtonItem14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim uc As New ucContainers
        AddNewDockContainerItem("Containers", "Containers Management", uc)
    End Sub


    Private Sub ButtonItemLogout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonItemLogout.Click
        While Bar2.Items.Count > 0
            Dim dockName As BaseItem = Bar2.Items(0)
            Bar2.Items.Remove(dockName)
        End While

        'dang xuat
        SetEnableSomeMenus(False)
        ButtonItemLogin.Enabled = True

        LoginOK = False

        ''Write log
        'Dim objLogController As New LogController
        'objLogController.Insert(enumAction.LogOut, "Log out")

        'Reload
        frmMain_Load(Nothing, Nothing)
    End Sub


    Private Sub ButtonItemExportFiles_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonItemExportFiles.Click
        Dim uc As ucFileManagement = New ucFileManagement(Me, enumFILE.Export)
        AddNewDockContainerItem("ExportFiles", "Export Files", uc)
        'If Bar2.SelectedDockContainerItem.Name = "DockContainerItem" + "ExportFiles" Then
        '    ButtonItemNewImportFile.Enabled = False
        '    ButtonItemNewExportFile.Enabled = True
        'ElseIf Bar2.SelectedDockContainerItem.Name = "DockContainerItem" + "ImportFiles" Then
        '    ButtonItemNewImportFile.Enabled = True
        '    ButtonItemNewExportFile.Enabled = False
        'End If
    End Sub

    Private Sub ButtonItemImportFiles_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonItemImportFiles.Click
        Dim uc As ucFileManagement = New ucFileManagement(Me, enumFILE.Import)
        AddNewDockContainerItem("ImportFiles", "Import Files", uc)
        ''If Bar2.SelectedDockContainerItem.Name = "DockContainerItem" + "ExportFiles" Then
        ''    ButtonItemNewImportFile.Enabled = False
        ''    ButtonItemNewExportFile.Enabled = True
        ''ElseIf Bar2.SelectedDockContainerItem.Name = "DockContainerItem" + "ImportFiles" Then
        ''    ButtonItemNewImportFile.Enabled = True
        ''    ButtonItemNewExportFile.Enabled = False
        ''End If
    End Sub

    Private Sub btnOilManagers_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOilManagers.Click
        Dim uc As ucChiPhiXangDau = New ucChiPhiXangDau()
        AddNewDockContainerItem("PushOil", "Push Oil Fee", uc)
    End Sub

    Private Sub btnAdvance_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdvance.Click
        'hiển thị phiếu tạm ứng
        Dim uc As New ucAdvanceVoucherNew()
        AddNewDockContainerItem("AdvanceVoucher", "Advance Voucher", uc)
    End Sub

    Private Sub btnPayment_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPayment.Click
        'hiển thị phiếu thu
        Dim uc As New ucPaymentVoucherNew()
        AddNewDockContainerItem("PaymentVoucher", " Payment Voucher", uc)
    End Sub

    Private Sub btnDebitNote_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        'Thống kê tổng giá mua bán
        Dim uc As New ucDebit(81)
        AddNewDockContainerItem("DebitNote", "Debit Note", uc)
    End Sub

    Private Sub btnStatiticBuyingSelling_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStatiticBuyingSelling.Click
        'Thống kê tổng giá mua bán
        Dim uc As New ucThongkeTongGiaMuaBan()
        AddNewDockContainerItem("BuyingSelling", "Buying/Selling Statitics", uc)

    End Sub

    Private Sub btnBuyingR_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim uc As New ucBuyingRate(10)
        AddNewDockContainerItem("BuyingRate", "Buying Rate", uc)
    End Sub


    Private Sub btnBuyingRate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim uc As New ucBuyingRate(10)
        AddNewDockContainerItem("BuyingRate", "Buying Rate", uc)
    End Sub

    Private Sub btCountries_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btCountries.Click
        'Dim frm As New frmCountries
        'frm.ShowDialog()
        'Dim uc As New ucCountries
        'AddNewDockContainerItem("Countries", "Countries", uc)
        'HT Code:
        AddNewDockContainerItem("Country", "Country", New ucCategories(enumCategories.Country))
    End Sub

    Private Sub btPorts_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btPorts.Click
        'Dim uc As New ucPort
        'AddNewDockContainerItem("Port", "Port", uc)
        'HT Code:
        AddNewDockContainerItem("Port", "Port", New ucCategories(enumCategories.Port))
    End Sub

    'Private Sub ButtonItem19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonItem19.Click
    '    Dim uc As New ucBookingFile
    '    AddNewDockContainerItem("Booking", "Booking", uc)
    'End Sub

#Region "Button Sy"
    Private Sub ButtonItemPartner_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonItemPartner.Click
        AddNewDockContainerItem("Partner", "Partner", New ucCategories(enumCategories.ForeignCompany))
    End Sub

    Private Sub btnFee_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFee.Click
        AddNewDockContainerItem("Fee", "Fee Management", New ucCategories(enumCategories.Fee))
    End Sub

    Private Sub btnVessel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVessel.Click
        AddNewDockContainerItem("Vessel", "Vessel Management", New ucCategories(enumCategories.Vessel))
    End Sub

    Private Sub btnAgent_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAgent.Click
        AddNewDockContainerItem("Agent", "Agent Management", New ucCategories(enumCategories.Agent))
    End Sub

    Private Sub btnAccessory_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAccessory.Click
        AddNewDockContainerItem("Accessory", "Accessory Management", New ucCategories(enumCategories.Accessory))
    End Sub

    Private Sub btnTruck_Accessory_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        AddNewDockContainerItem("Fix Progress", "Fix Progress Management", New ucTruck_Accessory(1))
    End Sub

    'Private Sub btnVoyage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    '    AddNewDockContainerItem("Voyage", "Voyage Management", New ucVoyage)
    'End Sub

    Private Sub btnUnit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUnit.Click
        AddNewDockContainerItem("Unit", "Unit Management", New ucCategories(enumCategories.Unit))
    End Sub

    Private Sub btnReceipts_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReceipts.Click
        Dim uc As New ucReceiptVouchersNew
        AddNewDockCategoriesItem("ReceiptVoucher", " Receipt Voucher", uc)
    End Sub
#End Region

    Private Sub btnTongChiPhi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTongChiPhi.Click
        Dim uc As New ucTongXangDau()
        AddNewDockContainerItem("StatisticOil", "Sum of Oil Fee", uc)
    End Sub

    Private Sub btnThanhToan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThanhToan.Click
        Dim uc As New ucOilfuel()
        AddNewDockContainerItem("PaymentOil", "Payment Oil Fee", uc)
    End Sub



    Private Sub ButtonItemChangeConnectDB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonItemChangeConnectDB.Click
        Dim frm As New frmChangeConnectDB
        frm.ShowDialog()
    End Sub

    Private Sub RibbonTabItemAccount_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RibbonTabItemAccount.Click

    End Sub

    Private Sub btnSlowFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSlowFile.Click
        Dim uc As New ucLoHangThanhToanCham()
        AddNewDockContainerItem("SlowFile", "Slow File", uc)
    End Sub

    Private Sub frmMain_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
        'If LoginOK Then
        '    'Write log
        '    Dim objLogController As New LogController
        '    objLogController.Insert(enumAction.LogOut, "Log out")
        'End If
    End Sub

    Private Sub btnRepairManagement_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRepairManagement.Click
        AddNewDockContainerItem("RepairManagement", "Repair Management", New ucTruck_Accessory(1))
    End Sub


    Private Sub ButtonItemLine_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonItemLine.Click
        AddNewDockContainerItem("Line", "Line Management", New ucCategories(enumCategories.Line))
    End Sub


    Private Sub btAccessPermission_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btAccessPermission.Click
        Dim uc As New ucRoleMenu
        AddNewDockCategoriesItem("AccessPermission", "Access Permission", uc)
    End Sub

    Private Sub ButtonItemParamaterConfig_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonItemParamaterConfig.Click
        Dim uc As New ucConfig
        AddNewDockCategoriesItem("ParamaterConfig", "Paramater Configuration", New ucCategories(enumCategories.Config))
    End Sub

    Private Sub btLineCont_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btLineCont.Click
        AddNewDockCategoriesItem("LineCont", "Conts of Line", New ucLineCont())
    End Sub

    Private Sub ButtonItemAdvanceDriver_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonItemAdvanceDriver.Click
        AddNewDockCategoriesItem("AdvanceDriver", "Advance Driver", New ucAdvanceDriverManagement())
    End Sub

    Private Sub btnContOfTNC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnContOfTNC.Click
        'AddNewDockCategoriesItem("ContOfTNC", "Cont of TNC Management", New ucContTNC())
        AddNewDockContainerItem("ContOfTNC", "Cont of TNC Management", New ucCategories(enumCategories.ContOfTNC))
    End Sub

    Private Sub btnAccessoryOfCont_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAccessoryOfCont.Click
        'AddNewDockCategoriesItem("AccessoryOfCont", "Accessory of Cont Management", New ucAccessory(2))
        AddNewDockCategoriesItem("AccessoryOfCont", "Accessory of Cont Management", New ucCategories(enumCategories.AccessoryOfCont))
    End Sub


    Private Sub btnRepairOfCont_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRepairOfCont.Click
        AddNewDockContainerItem("Fix Progress Cont", "Fix Progress Cont Management", New ucTruck_Accessory(2))
    End Sub

    Private Sub btnViewFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnViewFile.Click
        Dim frm As New frmXacNhanPhieu
        frm.ShowDialog()
    End Sub

    Private Sub btnContFee_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnContFee.Click
        AddNewDockCategoriesItem("Cont Fee", "Cont Fee Management", New ucContFee())
    End Sub

    Private Sub Bar2_DockTabClosed(ByVal sender As System.Object, ByVal e As DevComponents.DotNetBar.DockTabClosingEventArgs) Handles Bar2.DockTabClosed

    End Sub

    Private currentDock As DockContainerItem
    Private Sub Bar2_DockTabClosing(ByVal sender As System.Object, ByVal e As DevComponents.DotNetBar.DockTabClosingEventArgs) Handles Bar2.DockTabClosing
        'Nếu xóa 1 dock thì dock kế cận nó sẽ được selected
        'Nếu xóa dock ở bên trong thì dock ngay kế bên phải sẽ được selected
        'Nếu xóa dock ở bên phải ngoài cùng thì dock kế bên tay trái sẽ được selected
        Dim isFinish As Boolean = False
        For i As Integer = 0 To Bar2.Items.Count - 1
            Dim item As DockContainerItem = Bar2.Items(i)
            If item IsNot Bar2.SelectedDockContainerItem Then
                If item.Visible Then
                    'Lưu lại dock bên trái trái gần nhất
                    currentDock = item
                End If
            Else
                'Tìm dock kế bên tay phải gần nhất
                For j As Integer = i + 1 To Bar2.Items.Count - 1
                    item = Bar2.Items(j)
                    If item.Visible Then
                        'Tìm thấy dock bên tay phải gần nhất thì lưu lại
                        currentDock = item
                        isFinish = True
                        'Thoát ngay vòng for sau khi tìm thấy
                        Exit For
                    End If
                Next
                'Nếu tìm thấy currentDock thì thoát khỏi vòng for
                If isFinish Then
                    Exit For
                End If
            End If
        Next

        'Cập nhật lại dock hiện hành 
        Bar2.SelectedDockContainerItem = currentDock
    End Sub
End Class